package com.frx.extra.compare;

import java.text.ParseException;
import java.util.Arrays;

/**
 * Created by xurenfeng on 2019/2/15.
 */
public class Person implements Comparable<Person>{

    private String name;
    private int age;

    public Person(String name,int age){
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public int compareTo(Person p) {
        return this.age - p.age;
    }

    public static void main(String[] args){
        Person a = new Person("aa",24);
        Person b = new Person("bb",21);
        Person [] pp = {a,b};
        System.out.println("排序前:");
        for (Person p : pp){
            System.out.print(p.getName() + " ");
        }
        System.out.println();
        System.out.println("排序后:");
        Arrays.sort(pp);
        for (Person p : pp){
            System.out.print(p.getName() + " ");
        }
    }
}
